#!/usr/bin/env python3

import multiprocessing as mp
import os
import time

def Run(v, l, index, *args):
    print("child[%d] pid = " % index, os.getpid(), ", Run args: ", args)
    l.acquire()
    for i in range(1, 10):
        v.value += i
        print("child[%d] = %d" % (index, v.value))
    l.release()
    print("child exit....")


def main():
    print("main pid = ", os.getpid())

    v = mp.Value('i', 0)
    l = mp.Lock()

    for i in range(10):
        p = mp.Process(target=Run, args=(v, l, i))
        p.start()

if __name__ == "__main__":
    main()
